<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cjrtnc.leaningtech.com/4.2/loader.js"></script>
    <title>Document</title>
</head>

<body>
    <script>
        function base64ToBlob(base64Str, mimeType = 'application/octet-stream') {
  const base64Data = base64Str.replace(/^data:.*;base64,/, '');
  const binaryStr = atob(base64Data);
  const len = binaryStr.length;
  const uint8Array = new Uint8Array(len);
  for (let i = 0; i < len; i++) {
    uint8Array[i] = binaryStr.charCodeAt(i);
  }
  return new Blob([uint8Array], { type: mimeType });
}
function gb() {
            const imgBase64 = "UEsDBBQACAgIACKmXVsAAAAAAAAAAAAAAAAUAAQATUVUQS1JTkYvTUFOSUZFU1QuTUb+ygAA803My0xLLS7RDUstKs7Mz7NSMNQz4OXyTczM03XOSSwutlIAsXm5eLkAUEsHCHwCO+cqAAAAKwAAAFBLAwQKAAAIAAAipl1bAAAAAAAAAAAAAAAACQAAAE1FVEEtSU5GL1BLAwQUAAgICAAipl1bAAAAAAAAAAAAAAAACgAAAE1haW4uY2xhc3ONU11PE0EUPdOWblsXigWKiGJRPlpU6vdXiw80IZAsalICDzwNywhDtzvN7hSDz/4I333wGR8wIdEf4G/xFxij3lmaiLYYN5m9c++ee87Zubtffhx/BrCAagYxxC0kbPQhyTC4x/d52eP+Tvn51p5wNUOyKn2pnzLEi6X1NFJIW8jYOAf7D3j9INSiSSjVpqYRJ3oiVflFIH1d14HgzUoKAwy5ZeF5qsD97cIr4bmqKSYzGMR5CzkbQxhmGOrRSz5aJnvJUC06p2Q1VXcqm87fxiulnhZy9Np5G6O4wDDa5A1RU77L9YbUu7QLNfd1SPaLK6VuEWPzoo1xXGKwIjeeb7DdyNK6hQmGxCqXhEjU1LZgyDrSF8/azS0RrPEtjyo5R7ncW+eBNHmnmNC7kiwkHdNcobwZkeSLm710GJiktUI4HuxQ31APGEN/XXO3scpbHZFMXbUDVyxJk6SN0rzpookuKqVDHfDWqtC7ajvMJlHO4BZuW7hjzu0uw9RvAenvq4bo6Jwc5RJ3tQoOGN6ePpgO8IR0mYbviXDKUarRblW6DZ/VuHbQEj3gZ0//NEWNe15dakGf4X2GPllYKDAGe8X3RVDzeBiK0MIjhun/cm3hCcPEv6FmihEYk7hMP5q5YmDmV6P7FcrKFBnFvrmPYIfR4wLdk1ExTm2AfQLAVVyjmMYUpjvNrwlhSGc/wMr1xz8hdoTsRqI6nnqHEaqNH2MEOMLYG8be//x6GFEa+jzRARb6iW6YBAoUZzAQyeWJMktznsFsJDyLIkoU5yLx2Hdk2TcCxXE9cnsDNymmCDpP6x4eUJah3UM8RgVjvwBQSwcITnF+CnACAABpBAAAUEsBAhQAFAAICAgAIqZdW3wCO+cqAAAAKwAAABQABAAAAAAAAAAAAAAAAAAAAE1FVEEtSU5GL01BTklGRVNULk1G/soAAFBLAQIKAAoAAAgAACKmXVsAAAAAAAAAAAAAAAAJAAAAAAAAAAAAAAAAAHAAAABNRVRBLUlORi9QSwECFAAUAAgICAAipl1bTnF+CnACAABpBAAACgAAAAAAAAAAAAAAAACXAAAATWFpbi5jbGFzc1BLBQYAAAAAAwADALUAAAA/AwAAAAA=";
// 转换为 Blob（自动识别 MIME 类型，或手动指定）
const imgBlob = base64ToBlob(imgBase64);

// 生成 Blob URL 并在 img 标签中显示
const blobUrl = URL.createObjectURL(imgBlob, "data:application/java-archive");
// 用完后释放 Blob URL（避免内存泄漏）
//   URL.revokeObjectURL(blobUrl);
return blobUrl;
            }
        async function downloadFileToCheerpJ() {
            const response = await fetch(gb());
            const reader = response.body.getReader();
            const contentLength = +response.headers.get('Content-Length');

            const bytes = new Uint8Array(contentLength);

            let pos = 0;
            while (true) {
                const { done, value } = await reader.read();
                if (done)
                    break;
                bytes.set(value, pos);
                pos += value.length;
            }

            // Write to CheerpJ filesystem
            return new Promise((resolve, reject) => {
                var fds = [];
                cheerpOSOpen(fds, "/files/temp.jar.jar", "w", fd => {
                    cheerpOSWrite(fds, fd, bytes, 0, bytes.length, w => {
                        console.log(resolve)
                        cheerpOSClose(fds, fd, resolve);
                    });
                });
            });
        }

        ((async () => {
            await cheerpjInit({
                version: 17
            });
            cheerpjCreateDisplay(600, 900)
            await downloadFileToCheerpJ()
            cheerpjRunJar("/files/temp.jar.jar")
        })())
    </script>
</body>

</html>